package com.boarsoft.dubbo;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.utils.ReferenceConfigCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.boarsoft.soagov.svc.ServiceFinder;

@Component("dubboServiceFinder")
public class DubboServiceFinder implements ServiceFinder {
	@Autowired
	protected ApplicationConfig applicationConfig;
	@Autowired
	protected RegistryConfig registryConfig;

	@Value("${dubbo.mock.default}")
	protected String mock;

	@Override
	public <T> T getInvokeService(Class<?> interfaceClass, String group, String name, String version) {
		ReferenceConfig<T> rc = new ReferenceConfig<T>();
		rc.setApplication(applicationConfig);
		rc.setRegistry(registryConfig);
		rc.setGroup(group);
		rc.setVersion(version);
		rc.setInterface(interfaceClass);
		rc.setMock(mock);
		return ReferenceConfigCache.getCache().get(rc);
	}

}
